$sideBarWidthMin: 64px;

/* 临时定义 */
$menuTitleHover: #303030;

@mixin merge-style($sideBarWidth) {
  $menuActiveText: #7a80b4;

  .easy-title {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-weight: bold;
    line-height: 42px;
    background-color: var(--easy-bg-active-color);

    &::before {
      position: absolute;
      top: 50%;
      left: 0;
      width: 4px;
      height: 24px;
      content: '';
      background: var(--el-color-primary);
      border-radius: 4px;
      transform: translateY(-50%);
    }
  }

  .app-wrapper {
    position: relative;
    width: 100%;
    height: 100%;

    .sidebar-container.nav-horizontal {
      width: 0 !important;
    }
  }

  .sidebar-container {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1001;
    width: $sideBarWidth;
    height: 100%;
    overflow: visible;
    font-size: 0;
    background: var(--el-bg-color);
    border-right: 1px solid var(--easy-border-color);

    /* 展开动画 */
    transition: width var(--easy-transition-duration);

    .scrollbar-wrapper {
      overflow-x: hidden !important;
    }

    .el-scrollbar__bar.is-vertical {
      right: 0;
    }

    &.has-logo {
      .el-scrollbar.pc {
        /* logo: 48px、leftCollapse: 40px、leftCollapse-shadow: 4px */
        height: calc(100% - 92px);
      }

      /* logo: 48px */
      .el-scrollbar.mobile {
        height: calc(100% - 48px);
      }
    }

    &.no-logo {
      .el-scrollbar.pc {
        /* leftCollapse: 40px、leftCollapse-shadow: 4px */
        height: calc(100% - 44px);
      }

      .el-scrollbar.mobile {
        height: 100%;
      }
    }

    .is-horizontal {
      display: none;
    }

    a {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
    }

    .el-menu {
      height: 100%;
      background-color: transparent !important;
      border: none;
    }

    .el-sub-menu__title {
      &:hover {
        background-color: transparent;
      }
    }

    /* 无子集的激活菜单背景 */
    .is-active.outer-most > * {
      z-index: 1;
      color: #f8fafc;
    }

    .is-active.outer-most::before {
      background: var(--el-color-primary) !important;
    }
  }

  /* vertical 菜单折叠 */
  .el-menu--vertical {
    &:not(.el-menu--collapse) {
      width: $sideBarWidth;
    }

    .el-menu-item,
    .el-sub-menu__title {
      height: 50px;
      color: var(--easy-menu-text-color);
      background-color: transparent !important;

      &:hover,
      &:hover .el-text {
        color: $menuTitleHover;
      }

      div,
      span {
        height: 50px;
        line-height: 50px;
        color: var(--easy-menu-text-color);
        transition: color 0.3s;
      }
    }

    .el-sub-menu__title {
      &:hover {
        background-color: transparent;
      }
    }

    /* 无子集的激活菜单背景 */
    .is-active.outer-most > * {
      z-index: 1;
      color: #f8fafc !important;
    }

    .is-active.outer-most::before {
      background: var(--el-color-primary) !important;
    }
  }

  /* horizontal 菜单折叠 */
  .el-menu--horizontal {
    --el-menu-horizontal-sub-item-height: 50px;

    & > .el-sub-menu .el-sub-menu__icon-arrow {
      position: static !important;
      margin-top: 0;
    }

    .el-menu-item,
    .el-sub-menu__title {
      &:hover,
      &:hover .el-text {
        color: $menuTitleHover;
      }

      div,
      span {
        color: var(--easy-menu-text-color);
        transition: color 0.3s;
      }
    }

    .el-menu-item:not(.is-disabled):hover {
      background-color: transparent;
    }

    /* 无子菜单时激活 border-bottom */
    a > .is-active.submenu-title-noDropdown {
      border-bottom: 2px solid var(--el-menu-active-color);
    }

    .el-menu--popup {
      a > .is-active.submenu-title-noDropdown {
        border-bottom: none;
      }

      .el-menu-item {
        color: var(--easy-menu-text-color);

        span {
          font-size: 14px;
        }
      }

      .el-sub-menu__title {
        color: var(--easy-menu-text-color);
      }
    }

    /* 子菜单中还有子菜单 */
    .el-menu .el-sub-menu__title {
      min-width: $sideBarWidth !important;
      font-size: 14px;

      &:hover {
        color: $menuTitleHover !important;
      }
    }

    .nest-menu .el-sub-menu > .el-sub-menu__title,
    .el-menu-item {
      &:hover {
        color: $menuTitleHover !important;
      }
    }

    .el-menu-item.is-active {
      // color: $subMenuActiveText !important;
      transition: color 0.3s;
    }

    .el-menu-item.is-active.nest-menu > * {
      z-index: 1;
      color: #f8fafc;
    }

    .el-menu-item.is-active.nest-menu::before {
      background: var(--el-color-primary) !important;
    }
  }

  .el-menu--horizontal .el-menu .el-menu-item,
  .el-menu--horizontal .el-menu .el-sub-menu__title {
    padding: 0 14px 0 20px;
  }

  .horizontal-header {
    .horizontal-header-menu {
      flex: 1;
      align-items: center;
      min-width: 0;
      height: 100%;

      .el-menu-item,
      .el-sub-menu__title {
        padding-right: var(--el-menu-base-level-padding);
        color: var(--easy-menu-text-color) !important;

        &:hover {
          color: $menuTitleHover !important;
        }
      }

      .submenu-title-noDropdown,
      .el-sub-menu__title {
        height: 48px;
        line-height: 48px;

        svg {
          position: static !important;
        }
      }
    }

    .el-menu {
      width: 100% !important;
      height: 100%;
      background-color: transparent;
      border: none;
    }
  }

  .main-container {
    position: relative;
    flex: 1;
    height: 100vh;
    min-height: 100%;
    margin-left: $sideBarWidth;
    background: #f0f2f5;

    /* main-content 属性动画 */
    transition: margin-left var(--easy-transition-duration);

    .el-scrollbar__wrap {
      height: 100%;
      overflow: auto;
    }
  }

  .main-container.hide-side-bar,
  .hideSidebar .main-container.hide-side-bar {
    margin-left: 0 !important;
  }

  // 固定layout头部
  .lay-header {
    background-color: var(--el-bg-color);
  }

  .app-wrapper.hideSidebar {
    .sidebar-container {
      width: $sideBarWidthMin;
    }

    .main-container {
      margin-left: $sideBarWidthMin;
    }
  }

  .navbar-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 48px;
    cursor: pointer;
  }
}

body {
  $sideBarWidth: 210px;

  @include merge-style($sideBarWidth);

  .main-container {
    margin-left: $sideBarWidth;
  }

  /** 修复菜单收起时，激活菜单背景色 */
  .el-menu--collapse .el-sub-menu.is-active .el-sub-menu__title {
    color: var(--el-menu-active-color) !important;
  }

  .navbar-icon:hover {
    background: var(--easy-tool-color);
  }

  .el-menu-item,
  .el-sub-menu__title {
    height: 50px;
    color: var(--easy-menu-text-color);
    background-color: transparent !important;

    &::before {
      position: absolute;
      inset: 0 5px;
      margin: 4px 0;
      clear: both;
      content: '';
      background: transparent;
      border-radius: var(--easy-border-radius);
    }

    &:hover,
    &:hover .el-text {
      color: $menuTitleHover;
    }

    &:hover::before {
      background: var(--easy-tool-color);
    }

    div,
    span {
      height: 50px;
      line-height: 50px;
    }

    .el-text {
      z-index: 0;
    }
  }

  .el-menu--collapse > .el-menu-item > span,
  .el-menu--collapse > .el-sub-menu > .el-sub-menu__title > span {
    width: 100%;
    visibility: visible;
  }

  .el-sub-menu .el-sub-menu__icon-arrow {
    z-index: 0;
  }
}
